package com.atguigu.spzx.cloud.order.service.impl;

import com.atguigu.spzx.cloud.order.feign.UserFeignClient;
import com.atguigu.spzx.cloud.order.entity.Order;
import com.atguigu.spzx.cloud.order.mapper.OrderMapper;
import com.atguigu.spzx.cloud.order.service.OrderService;
import com.atguigu.spzx.cloud.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OrderMapper orderMapper ;
    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public Order findOrderByOrderId(Long orderId) {
        Order order = orderMapper.findOrderByOrderId(orderId);
        // 远程调用
        User user = userFeignClient.queryById(order.getUserId());
        order.setUser(user);
        return order;
    }
    /*@Override
    public Order findOrderByOrderId(Long orderId) {
        // 根据id查询订单数据
        Order order = orderMapper.findOrderByOrderId(orderId);
        //发起远程调用
        User user = restTemplate.getForObject
                // 服务提供方的服务ip地址和端口号可以使用服务提供方的服务名称进行替换
                ("http://spzx-cloud-user/u/uid/"+order.getUserId(),User.class);
        order.setUser(user);
        //返回
        return order;
    }*/

}